<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="head-title">
        <title>Check Material Request State| Merlion's ERP System</title>
    </ui:define>

    <ui:define name="content">
        
        <p:panel id="panel" header="Change Material Request State"> 
            <p:ajaxStatus style="width:16px;height:16px;">   
                <f:facet name="start">   
                    <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                </f:facet> 

                <f:facet name="complete">   
                    <h:outputText value="" />   
                </f:facet>   
            </p:ajaxStatus>
            
            <p:messages id="statusMessages"/>

            <h:form prependId="false">    
                <p:dataTable id="table1" var="materialRequest" value="#{viewMaterialRequestManagerBean.processMaterialRequest}" 
                             dynamic="true" paginator="true" rows="10" emptyMessage="No Pending Material Request Record" 
                             selection="#{viewMaterialRequestManagerBean.selectedMaterialRequest}" onRowSelectUpdate="display">
                    <p:column selectionMode="single"/>

                    <p:column sortBy="#{materialRequest.materialRequestId}" filterBy="#{materialRequest.materialRequestId}"> 
                        <f:facet name="header"> 
                            <h:outputText value="Material Request ID" /> 
                        </f:facet> 
                        <h:outputText value="#{materialRequest.materialRequestId}" /> 
                    </p:column> 
                    
                    <p:column sortBy="#{materialRequest.currentDate}" filterBy="#{materialRequest.currentDate}"> 
                        <f:facet name="header"> 
                            <h:outputText value="Material Request Date" /> 
                        </f:facet> 
                        <h:outputText value="#{materialRequest.currentDate}" /> 
                    </p:column>

                    <p:column sortBy="#{materialRequest.requestState}" filterBy="#{materialRequest.requestState}"> 
                        <f:facet name="header"> 
                            <h:outputText value="Material Request State" /> 
                        </f:facet> 
                        <h:outputText value="#{materialRequest.requestState}" /> 
                    </p:column>

                    <f:facet name="footer">  
                        <p:commandButton value="View Request Detail" image="ui-icon ui-icon-search" update="display1 mrMaterialOrderT" oncomplete="ViewDialog.show()"/>
                        
                    </f:facet>

                </p:dataTable>

                <p:dialog header="Material Request Detail" widgetVar="ViewDialog" width="450" height="300" resizable="true" showEffect="clip" hideEffect="fold">
                    <h:panelGrid id="display1" columns="2" cellpadding="5">
                        <h:outputText value="Material Request ID:"/>
                        <h:outputText value="#{viewMaterialRequestManagerBean.selectedMaterialRequest.materialRequestId}"/>
                    </h:panelGrid>
                    
                    <p:dataTable var="MaterialOrder" value="#{viewMaterialRequestManagerBean.selectedMaterialRequest.materialOrders}" 
                                 dynamic="true" emptyMessage="No Material Order For This Request" id="mrMaterialOrderT">
                        <p:column sortBy="#{MaterialOrder.materialOrderId}">
                            <f:facet name="header">
                                <h:outputText value="Material Order ID"/>
                            </f:facet>
                            <h:outputText value="#{MaterialOrder.materialOrderId}"/>                        
                        </p:column>
                                                                    
                        <p:column sortBy="#{MaterialOrder.materialOrderState}">
                            <f:facet name="header">
                                <h:outputText value="Material Order State"/>
                            </f:facet>
                            <h:outputText value="#{MaterialOrder.materialOrderState}"/>                        
                        </p:column> 
                        
                        <f:facet name="footer"> 
                        <p:commandButton value="Change State" actionListener="#{viewMaterialRequestManagerBean.changeState(event)}" 
                                         update="table1 statusMessages" oncomplete="ViewDialog.hide()" />
                        </f:facet>                        
                    </p:dataTable>
                  
                </p:dialog>                
            </h:form>
        </p:panel>    
    </ui:define>
</ui:composition>
